package com.hyt.it.ogt.kq.main.controller.gov;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.exception.annotation.ThrowsAdvice;
import com.hyt.it.ogt.kq.common.bm.swagger.BmApiVersionConstant;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.gov.model.param.GatherImportFileParam;
import com.hyt.it.ogt.kq.service.gov.model.param.GatherPageParam;
import com.hyt.it.ogt.kq.service.gov.model.vo.GatherPageVO;
import com.hyt.it.ogt.kq.service.gov.service.IExamAfterGatherService;
import com.hyt.log.annotation.Log;
import com.hyt.progress.creator.anno.ProgressAnno;
import com.hyt.progress.service.ProgressManager;
import com.hyt.swagger.ApiVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 汇总系统考试结果上传接口 前端控制器
 * </p>
 *
 * @author huangyh
 * @since 2021-03-08
 */
@Api(tags = "43.汇总系统考试结果上传接口", value = "汇总系统考试结果上传接口")
@ApiSort(value = 43)
@RestController
@RequestMapping("/kw/gov/examAfterGather")
public class ExamAfterGatherController extends BaseController {

    @Resource
    IExamAfterGatherService iExamAfterGatherService;

    @ApiOperation(value = "43.1.1 汇总系统列表查询", response = GatherPageVO.class)
    @ApiOperationSort(value = 1)
    @ApiVersion(group = BmApiVersionConstant.V2_4_11)
    @ThrowsAdvice(code = 31431101, print = "汇总系统列表查询失败")
    @Log(module = "汇总数据管理", business = "汇总系统列表查询", keepArchives = false, isSaveResponseData = false)
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ApiResponse<IPage<GatherPageVO>> gatherPage(@RequestBody GatherPageParam param) {
        return ApiResponse.<IPage<GatherPageVO>>builder()
                .code(Constant.RESPONSE_CODE_SUCCESS)
                .data(iExamAfterGatherService.gatherPage(param))
                .build();
    }

    @ApiOperation(value = "43.2.1 汇总系统数据包导入", response = GatherPageVO.class)
    @ApiOperationSort(value = 2)
    @ApiVersion(group = BmApiVersionConstant.V2_4_11)
    @ThrowsAdvice(code = 31432101, print = "汇总系统数据包导入失败")
    @Log(module = "汇总数据管理", business = "汇总系统数据包导入")
    @RequestMapping(value = "/importFile", method = RequestMethod.POST)
    public ApiResponse<String> importFile(@Validated @RequestBody GatherImportFileParam param, BindingResult bindingResult) {
        this.checkValid(bindingResult);

        String userId = getUserId();
        param.setCurrentLoginUserId(userId);
        return ApiResponse.<String>builder()
                .code(Constant.RESPONSE_CODE_SUCCESS)
                .data(iExamAfterGatherService.importFile(param))
                .build();
    }

    @ApiOperation(value = "43.3.1 汇总系统数据包删除", response = Boolean.class)
    @ApiOperationSort(value = 3)
    @ApiVersion(group = BmApiVersionConstant.V2_4_11)
    @ProgressAnno(errorCode = 31433101, timeoutSeconds = 10 * 60)
    @Log(module = "汇总数据管理", business = "汇总系统数据包删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public void deleteGather(@RequestParam String id) {
        String userId = getUserId();
        Boolean deleteGather = iExamAfterGatherService.deleteGather(id, userId);
        ProgressManager.finish(deleteGather);
    }
}
